package com.jsb.laundry.common.mq.confirm_receive_deadLetter;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 用户确认收货配置 ( 7天后自动确认收货 结算订单、调整状态 )
 */
@Configuration
public class UserConfirmReceiveOrderConfig {
    /**
     * 确认收货 交换机
     */
    public static final String userConfirmReceiveOrderExchange = "user_auto_receive_order_exchange_7";

    /**
     * 确认收货 队列
     */
    public static final String userConfirmReceiveOrderQueue = "user_auto_receive_order_queue_7";

    /**
     * 确认收货 路由key
     */
    public static final String userConfirmReceiveOrderRoutingKey = "user_auto_receive_order_routing_key_7";
    /**
     * 确认收货 死信交换机
     */
    public static final String userConfirmReceiveOrderDLExchange = "user_auto_receive_order_dl_exchange_7";

    /**
     * 确认收货 死信队列
     */
    public static final String userConfirmReceiveOrderDLQueue = "user_auto_receive_order_dl_queue_7";
    /**
     * 确认收货 死信路由
     */
    public static final String userConfirmReceiveOrderDLRoutingKey = "user_auto_receive_order_dl_routing_key_7";
    /**
     * 7天
     */
    public static final Integer autoReceiveOrderTime = 1000 * 60 * 60 * 24 * 7;
    /**
     * 声明确认收货队列
     */
    @Bean
    public Queue userConfirmReceiveOrderQueue() {
        //设置死信交换机、死信RoutingKey
        return QueueBuilder
                .durable(userConfirmReceiveOrderQueue)
                .deadLetterExchange(userConfirmReceiveOrderDLExchange)
                .deadLetterRoutingKey(userConfirmReceiveOrderDLRoutingKey)
                //设置TTL 7天 单位是ms
                // .ttl(1000 * 60 * 60 * 24 * 7)
                .build();
    }

    /**
     * 声明确认收货交换机
     */
    @Bean
    public DirectExchange userConfirmReceiveOrderExchange() {
        return new DirectExchange(userConfirmReceiveOrderExchange);
    }


    /**
     * 绑定确认收货队列 到 确认收货交换机
     */
    @Bean
    public Binding userConfirmReceiveOrderBinding(Queue userConfirmReceiveOrderQueue, DirectExchange userConfirmReceiveOrderExchange) {
        return BindingBuilder.bind(userConfirmReceiveOrderQueue).to(userConfirmReceiveOrderExchange).with(userConfirmReceiveOrderRoutingKey);
    }


    /**
     * 声明死信队列
     */
    @Bean
    public Queue userConfirmReceiveOrderDLQueue() {
        return new Queue(userConfirmReceiveOrderDLQueue);
    }

    /**
     * 声明死信交换机
     */
    @Bean
    public DirectExchange userConfirmReceiveOrderDLExchange() {
        return new DirectExchange(userConfirmReceiveOrderDLExchange);
    }

    /**
     * 绑定死信队列到死信交换机
     */
    @Bean
    public Binding userConfirmReceiveOrderDLBinding(Queue userConfirmReceiveOrderDLQueue, DirectExchange userConfirmReceiveOrderDLExchange) {
        return BindingBuilder.bind(userConfirmReceiveOrderDLQueue).to(userConfirmReceiveOrderDLExchange).with(userConfirmReceiveOrderDLRoutingKey);
    }


}
